﻿using System.Collections;
using UnityEngine;


public class SceneController : MonoBehaviour
{
    public enum SCENE
    {
        MovieDaydreamer, MovieAgan, MovieEndless, TemplateAgan, SceneWork, SceneSport, SceneMusic, Action10, OldScenePhone,
        Action1, Action2, Action3, Action4, Action5, Action6, Else
    }

    [Tooltip("建议录视频使用")]
    public SCENE activeScene;

    [Header("Available Selection")]
    [Tooltip("某些场景须指定角色，选择上面场景，点击按钮，人物角色会自动选择；对角色无要求的场景需要用户选择")]
    public GameObject activeCharacter;

    [HideInInspector]
    public string textInput;
    
    public string sceceText;

    private CharacterController characterController;
    private BSearcherController BSearcherController;

    // Use this for initialization
    void Start()
    {
        
    }

    public void SetScene()
    {
        // Get controllers
        characterController = GetComponent<CharacterController>();
        BSearcherController = GetComponent<BSearcherController>();

        if (!characterController)
            Debug.LogError("Character controller missing! Please mount it to the gameobject Controller!");
        if (!BSearcherController)
            Debug.LogError("BSearcher controller missing! Please mount it to the gameobject Controller!");

        switch (activeScene)
        {
            case SCENE.MovieAgan:
                BSearcherController.scene = BSearcherController.Scene.MovieAgan;
                foreach (var c in characterController.characters)
                    if (c.name.Equals("Ch33_nonPBR"))
                        activeCharacter = c;
                sceceText = "ls example_agan";
                textInput = "There is a normal agan_room$.\nThere is a pingpongpaddle and a book on a pingpang table$.\nThere is a lovely formal bed$.\nThere are three chairs at the left of a couch$.\n\nGump walks to the woodentable.\n\ncamera front\n\nGump walks to the bed.\nGump stands.\n\nGump walks to the sofa.\nGump sits on the sofa.\n\ncamera right\n\nGump walks to the chair.\nGump sits on the chair.\n\nGump stands while Gump is putting with the cap.\n\nGump runs to the road.";
                break;

            case SCENE.MovieDaydreamer:
                BSearcherController.scene = BSearcherController.Scene.MovieDaydreamer;
                foreach (var c in characterController.characters)
                    if (c.name.Equals("Ch31_nonPBR"))
                        activeCharacter = c;
                sceceText = "ls example_daydreamer";
                textInput = "There is an organized office room and an organized bookcase$.\nThere is a cabinet with two closets$.\nThere is an organized office table$.\nA messy dining table and a dining table is in the office room$.\nThere is a chair2 near the bookcase$.\nA tv is on a table$. \nA desklamp  is on a table near the bookcase$.\nWalter sits on the chair while Walter is playing with the laptop.\nWalter walks to the armchair.Walter sits on the armchair.\nWalter sits on the chair.Walter sits while Walter is playing.";
                break;

            case SCENE.MovieEndless:
                BSearcherController.scene = BSearcherController.Scene.MovieEndless;
                sceceText = "ls example_endless";
                textInput = "ls example_endless\nTom walks to the washbasin.\nTom stands while Tom is washing dishes.\nTom walks to the window.\nTom walks to the sofa.\nTom stands while Tom is pulling the sofa.\nTom sits on the sofa.\nTom sits on the chair and Tom is playing with the laptop.";
                Debug.Log("该场景效果较差，不建议录制视频；另外，该场景无指定角色，可由您自行选择活动角色！");
                break;

            case SCENE.SceneSport:
                BSearcherController.scene = BSearcherController.Scene.SceneWork;
                foreach (var c in characterController.characters)
                    if (c.name.Equals("Ch37_nonPBR"))
                        activeCharacter = c;
                sceceText = "ls example_sport";
                textInput = "ls example_sport\nMary walks to the sandbag.\nMary stands and Mary is warming.\nMary stands while Mary is punching boxingbag.\nMary stands while Mary is hooking boxingbag.\nMary walks to the desk.\nMary stands while Mary is drinking soda.";
                break;

            case SCENE.SceneWork:
                BSearcherController.scene = BSearcherController.Scene.SceneWork;
                foreach (var c in characterController.characters)
                    if (c.name.Equals("Ch17_nonPBR"))
                        activeCharacter = c;
                sceceText = "ls example_work";
                textInput = "ls example_work\nWorker walks to the saw.\nWorker turns leftly.\nWorker stands while Worker is sawing the wood.\nWorker walks to the hammer.\nWorker stands while Worker is hammering the nail into the wood.\nWorker walks to the table.\nWorker stands while Worker draws the design diagram.";
                break;

            case SCENE.SceneMusic:
                BSearcherController.scene = BSearcherController.Scene.SceneMusic;
                foreach (var c in characterController.characters)
                    if (c.name.Equals("Ch29_nonPBR"))
                        activeCharacter = c;
                sceceText = "ls example_music";
                textInput = "ls example_music\nAnny walks to the recorder.\nAnny stands while Anny is pushing the record button.\nAnny sits on the chair and Anny is playing the piano.\nAnny sits on the chair while Anny sings with microphone.";
                break;

            case SCENE.Action10:
                BSearcherController.scene = BSearcherController.Scene.Action10;
                Debug.Log("该选择有多场景，无指定角色，可由您自行选择活动角色！");
                break;
            
            case SCENE.Action1: // 找文件
                BSearcherController.scene = BSearcherController.Scene.Action10;
                foreach (var c in characterController.characters)
                    if (c.name.Equals("Ch37_nonPBR"))
                        activeCharacter = c;
                sceceText = "ls example_action1";
                textInput = "Jane stands while Jane is looking for the file.";
                break;
            
            case SCENE.Action2: // 游戏手柄
                BSearcherController.scene = BSearcherController.Scene.Action10;
                foreach (var c in characterController.characters)
                    if (c.name.Equals("Ch37_nonPBR"))
                        activeCharacter = c;
                sceceText = "ls example_action2";
                textInput = "Jane sits on the chair while Jane is playing.";
                break;
            
            case SCENE.Action3: // 画框
                BSearcherController.scene = BSearcherController.Scene.Action10;
                foreach (var c in characterController.characters)
                    if (c.name.Equals("Ch37_nonPBR"))
                        activeCharacter = c;
                sceceText = "ls example_action3";
                textInput = "Jane stands while Jane is hanging a photo frame.";
                break;

            case SCENE.OldScenePhone:
                BSearcherController.scene = BSearcherController.Scene.OldScenePhone;
                foreach (var c in characterController.characters)
                    if (c.name.Equals("Ch42_nonPBR"))
                        activeCharacter = c;
                sceceText = "ls example_angry";
                textInput = "camera front\n\nThere is a blackboard in a meetingroom$.\nThere is an arranged table in the meetingroom$.\nA modernchair is near a big couch in the meetingroom$.\nThere are two wardrobes in the meetingroom$.\nA stool is in the meetingroom$.\nThere are two lamps in the meetingroom$.\n\nTom sits on a modernchair.\nTom sits while Tom calls with phone.\nTom sits madly.\nTom stands.\n\ncamera back\n\nTom walks to the stool.\nTom walks sadly to the blackboard.\n\nTom turns rightly.\nTom stands while Tom writes.\n\nTom turns leftly.\n\ncamera front\n\nTom walks to the modernchair.\n\nTom sits on the modernchair.\nTom sits angrily.\nTom sits bitterly.\nTom stands.\n\nTom walks unbelievably to the road.";
                break;
            
            case SCENE.Else:
                BSearcherController.scene = BSearcherController.Scene.Else;
                Debug.Log("无指定角色，可由您自行选择活动角色！");
                textInput = "[TIP] defint it by yourself!";
                sceceText = "";
                break;
        }

        if (activeCharacter)
            characterController.activeCharacter = activeCharacter;
        
        if (characterController.activeCharacter)
            characterController.SetActiveChar();
    }

    // Update is called once per frame
    void Update()
    {

    }
}
